<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      ul .green{
        display: inline;
        color: red;
      }
    </style>
  </head>
  <body>
    <div class="the_div">
      <p>我是p标签</p>
      <h3>我是h3</h3>
      <h3>我是h3</h3>
      <h3>我是h3</h3>
      <a id="theA" href="#">我是一个a标签</a>
      <ul>
        <li>北京</li>
        <li>天津</li>
        <li>南京</li>
      </ul>
      <ol class="my_li">
        <li>大张</li>
        <li>大王</li>
        <li>大狗</li>
      </ol>
      <ul class="my_li">
        <li>小明</li>
        <li>小红</li>
        <li>小蓝</li>
      </ul>
    </div>
    <script>
      // 练习1. 通过id获取到a标签 (可以自己给a添加id)
      // 1.获取元素
      const aid = document.querySelector('#theA')

      console.log('------------------------------\n第二题');
      // 练习2. 通过标签名 获取到所有h3标签, 并输出在控制台（提示：for循环遍历）
      const h3 = document.querySelectorAll('h3')
      console.log(h3)
      for (let i = 0; i <= h3.length - 1; i++) {
        console.log(h3[i])
        console.log(h3[i].innerHTML)
      }

      console.log('------------------------------\n第三题');
      // 通过querySelectAll() 获取所有的li标签
      const li = document.querySelectorAll('li')
      // console.log(li);
      for (let i = 0; i <= li.length - 1; i++) {
        // console.log(li[i]);
        console.log(li[i].innerHTML)
      }

      console.log('------------------------------\n第四题');
      // 通过querySelectAll() 获取所有小字开头的名字的li标签
      const little = document.querySelectorAll('ul.my_li li')
      for (let i = 0; i <= h3.length - 1; i++) {
        console.log(little[i].innerHTML);
      }
      console.log('------------------------------\n第五题');
      // 练习5. 给<li>小红</li> 内容改成小六，字体颜色变成红色
      const oldsix = document.querySelectorAll('ul.my_li li')
      for (let i = 0; i <= h3.length - 1; i++) {
        if(oldsix[i].innerHTML === '小红'){
          oldsix[i].innerHTML = '小六'
          console.log(oldsix[i].innerHTML);
        }
      }
      const oldsix2 = document.querySelector('ul.my_li li:nth-child(2)')
      console.log(oldsix2.innerHTML);

      console.log('------------------------------\n第六题');
      // 练习6. 给<li>天津</li> 添加类名，样式修改背景色绿色
      const greenTianjin = document.querySelector('ul li:nth-child(2)')
      greenTianjin.classList.add('green')
      greenTianjin.style.backgroundColor = 'green'

    </script>
  </body>
</html>
